<?php
    
    @include_once('connect.php');
    header("Access-Control-Allow-Origin: *");
    $res = [];

    //前端接受数据
    $name = $_GET['username'] ;

    // $name = 'cc';

    if($name){
        //联表查询
        //查询两个表中的同一个变量一样的，这样可以获取到两个表中这个用户的信息以及这个商品的信息
        $sql = "SELECT * FROM cart2,goods_list1 WHERE username = '$name' AND cart2.goods_id = goods_list1.goods_id";
        $ggo = mysqli_query($connect , $sql);
        
        $list = [];

        while($arr=mysqli_fetch_array($ggo)){
            array_push($list,$arr);
        }

        if($list) {
            $res['status'] = true ;
            $res['msg'] = '数据请求成功';
            $res['data'] = $list ;
        } else {
            $res['status'] = false ;
            $res['msg'] = '数据库错误';
        }
        
    }else{
        $res['status'] = false ;
        $res['msg'] = '前端数据有误';
    }

    echo(json_encode($res , JSON_UNESCAPED_UNICODE)) ;